/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package devbureau.fstore.common;

/**
 *
 * @author buyakov
 */
public enum StoreItemOrderDir {
      desc
    , asc;

    /**Converts string to enum value
     * Case insensitive.
     * @param string value
     * @return enum equivalent or null, if can't be termined
     */
    public static StoreItemOrderDir get(String s) {
        StoreItemOrderDir field = null;
        try {
            StoreItemOrderDir[] enumConstants = StoreItemOrderDir.class.getEnumConstants();
            for(StoreItemOrderDir enumConst : enumConstants){
                if(enumConst.toString().toLowerCase().equals(s.toLowerCase())){
                    field = enumConst;
                    break;
                }
            }
        } catch (Exception e) {
            //swallow it
        }
        return field;
    }

    public static StoreItemOrderDir invert(StoreItemOrderDir dir){
        return dir == asc ? desc : asc;
    }
}
